package script;

import domain.User;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SpelHeelo {



    public static void main(String[] args) {
        ExpressionParser expressionParser = new SpelExpressionParser();
        Expression expression = expressionParser.parseExpression("'Hellow' + 'World'");
        String message = (String) expression.getValue();
        System.out.println(message);


        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression("'HelloWorld'.concat('!')");
        String msg = exp.getValue(String.class);
        System.out.println(msg);

        User user = new User();
        user.setName("chengxq");
        user.setCredits(100);

        ExpressionParser parse2 = new SpelExpressionParser();
        EvaluationContext context = new StandardEvaluationContext(user);
        String userName = (String) parse2.parseExpression("name").getValue(context);
        System.out.println(userName);


    }


}
